package com.xzy.learn.spring.bean.creation;

import com.xzy.learn.spring.entity.Student;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Map;

/**
 * 实例化 Bean 的普通方式
 *
 * @author xzy.xiao
 * @date 2022/6/1  10:52
 */
public class NormalBeanCreationDemo {
    public static void main(String[] args) {
        normalBeanCreation();
    }

    /**
     * 普通的创建 Bean 的方式
     */
    public static void normalBeanCreation() {
        ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("classpath:/META-INF/normal-bean-creation.xml");

        Map<String, Student> beansOfStudent = classPathXmlApplicationContext.getBeansOfType(Student.class);
        System.out.println("\nbeans of Student class：");
        beansOfStudent.forEach((id, bean) -> {
            System.out.println(id + " -> " + bean);
        });

        Map<String, FactoryBean> beansOfFactoryBean = classPathXmlApplicationContext.getBeansOfType(FactoryBean.class);
        System.out.println("\nbeans of FactoryBean class：");
        beansOfFactoryBean.forEach((id, bean) -> {
            System.out.println(id + " -> " + bean);
        });
    }
}
